var banner = document.querySelector('.container .imgarea a');
var tittleUlDom = document.querySelector('.container .slidebar ul');

function init() {
  loadTittle();
  //startBanner();
}
/**
 * 启动图片切换
 * @returns
 */
var curIndex = 0;
var timerId = null;

function startBanner() {
  if (timerId) {
    return;
  }
  timerId = setInterval(() => {
    curIndex++;
    if (curIndex >= data.length) {
      curIndex = 0;
    }
    var item = data[curIndex];
    banner.style.backgroundImage = `url(${item.img})`;
    banner.style.backgroundColor = item.bg;

    var lastLi = tittleUlDom.querySelector('.active');
    if (lastLi) {
      lastLi.className = 'movieitem';
    }

    var curLi = tittleUlDom.children[curIndex];
    if (curLi) {
      curLi.className = 'movieitem active';
    }
  }, 2000);
}

/**
 * 加载标题
 */
function loadTittle() {
  for (var i = 0; i < data.length; i++) {
    var item = data[i];
    var li = document.createElement('li');
    li.innerHTML = `<span class="moviename">${item.title}</span>
    <span class="moviedesc">${item.desc}</span>`;
    li.className = i === 0 ? 'movieitem active' : 'movieitem';
    li.setAttribute('data-index', i);

    tittleUlDom.appendChild(li);
  }
}
init();
